/**
 * 
 */
package com.netflexitysolutions.amazonws.s3;

import com.amazonaws.s3.doc._2006_03_01.AmazonS3;
import java.util.List;

import com.netflexitysolutions.amazonws.s3.internal.operations.CreateBucketOperation;
import com.netflexitysolutions.amazonws.s3.internal.operations.DeleteBucketOperation;
import com.netflexitysolutions.amazonws.s3.internal.operations.DeleteObjectOperation;
import com.netflexitysolutions.amazonws.s3.internal.operations.GetBucketAccessControlPolicyOperation;
import com.netflexitysolutions.amazonws.s3.internal.operations.GetBucketLoggingStatusOperation;
import com.netflexitysolutions.amazonws.s3.internal.operations.GetObjectAccessControlPolicyOperation;
import com.netflexitysolutions.amazonws.s3.internal.operations.GetObjectOperation;
import com.netflexitysolutions.amazonws.s3.internal.operations.ListAllBucketsOperation;
import com.netflexitysolutions.amazonws.s3.internal.operations.ListBucketOperation;
import com.netflexitysolutions.amazonws.s3.internal.operations.PutObjectInlineOperation;
import com.netflexitysolutions.amazonws.s3.internal.operations.PutObjectOperation;
import com.netflexitysolutions.amazonws.s3.internal.operations.SetBucketAccessControlPolicyOperation;
import com.netflexitysolutions.amazonws.s3.internal.operations.SetBucketLoggingStatusOperation;
import com.netflexitysolutions.amazonws.s3.internal.operations.SetObjectAccessControlPolicyOperation;
import java.io.File;

/**
 * @author netflexity
 *
 */
public class S3Soap implements S3 {

	private String accessKey;
	private String secretKey;
	private AmazonS3 service;
	
	/**
	 * @param service
	 * @param accessKey
	 * @param secretKey
	 */
	public S3Soap(AmazonS3 service, String accessKey, String secretKey) {
		this.service = service;
		this.accessKey = accessKey;
		this.secretKey = secretKey;
	}

	/* (non-Javadoc)
	 * @see com.netflexitysolutions.amazonws.s3.internal.S3#listAllMyBuckets()
	 */
	public List<S3Bucket> listAllMyBuckets() throws S3Exception {
		return new ListAllBucketsOperation(this).execute();
	}

    public S3Bucket listBucket(String bucket) throws S3Exception {
        return listBucket(bucket, null, null, null, -1);
    }
    
    public S3Bucket listBucket(String bucket, String prefix, String marker, String delimiter, int maxKeys) throws S3Exception {
        return new ListBucketOperation(this, bucket, prefix, marker, delimiter, maxKeys).execute();
    }

    public S3Bucket createBucket(String bucket) throws S3Exception {
        return createBucket(bucket, null);
    }

    public S3Bucket createBucket(String bucket, List<S3Grant> acl) throws S3Exception {
        return new CreateBucketOperation(this, bucket, acl).execute();
    }

    public S3ServerResponseStatus deleteBucket(String bucket) throws S3Exception {
        return new DeleteBucketOperation(this, bucket).execute();
    }

    public S3GetObjectResponse getObject(String bucket, String key, boolean loadMetadata, boolean loadData, boolean inlineData) throws S3Exception {
        return new GetObjectOperation(this, bucket, key, loadMetadata, loadData, inlineData).execute();
    }

    public S3ServerResponse putObject(S3Object object, String bucket) throws S3Exception {
        File file = new File("someFile");
        return new PutObjectOperation(this, object, bucket, file).execute();
    }

    public S3ServerResponse putObjectInline(S3Object object, String bucket) throws S3Exception {
        return new PutObjectInlineOperation(this, object, bucket).execute();
    }

    public S3ServerResponseStatus deleteObject(String bucket, String key) throws S3Exception {
        return new DeleteObjectOperation(this, bucket, key).execute();
    }

    public S3AccessControlPolicy getObjectAccessControlPolicy(String bucket, String key) throws S3Exception {
        return new GetObjectAccessControlPolicyOperation(this, bucket, key).execute();
    }

    public S3ServerResponseStatus setObjectAccessControlPolicy(String bucket, String key, List<S3Grant> acl) throws S3Exception {
        return new SetObjectAccessControlPolicyOperation(this, bucket, key, acl).execute();
    }

    public S3AccessControlPolicy getBucketAccessControlPolicy(String bucket) throws S3Exception {
        return new GetBucketAccessControlPolicyOperation(this, bucket).execute();
    }

    public S3ServerResponseStatus setBucketAccessControlPolicy(String bucket, List<S3Grant> acl) throws S3Exception {
        return new SetBucketAccessControlPolicyOperation(this, bucket, acl).execute();
    }

    public S3LoggingSettings getBucketLoggingStatusOperation(String bucket) throws S3Exception {
        return new GetBucketLoggingStatusOperation(this, bucket).execute();
    }

    public void setBucketLoggingStatusOperation(String bucket, S3LoggingSettings loggingSettings) throws S3Exception {
        String empty = new SetBucketLoggingStatusOperation(this, bucket, loggingSettings).execute();
    }


	/* (non-Javadoc)
	 * @see com.netflexitysolutions.amazonws.s3.internal.S3#getAccessKey()
	 */
	public String getAccessKey() {
		return accessKey;
	}

	/**
	 * @param accessKey the accessKey to set
	 */
	public void setAccessKey(String accessKey) {
		this.accessKey = accessKey;
	}

	/* (non-Javadoc)
	 * @see com.netflexitysolutions.amazonws.s3.internal.S3#getSecretKey()
	 */
	public String getSecretKey() {
		return secretKey;
	}

	/**
	 * @param secretKey the secretKey to set
	 */
	public void setSecretKey(String secretKey) {
		this.secretKey = secretKey;
	}

	/* (non-Javadoc)
	 * @see com.netflexitysolutions.amazonws.s3.S3#getService()
	 */
	public AmazonS3 getService() {
		return service;
	}
}
